/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.leospa.main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.Hashtable;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.Timer;

import com.leospa.bean.Command_0;
import com.leospa.bean.TimerCounter;
import com.leospa.clients.SerialClient;
import com.leospa.properties.ConfigPropertiesFile;
import com.leospa.properties.ContentPropertiesFile;

/**
 *
 * @author ADMIN
 */
public class ThanksYouScreen {

	/**
	 * Creates new form ConfirmationScreen
	 */
	int count = 0;
	Timer timer ;
	Command_0 command_0;
	MainScreen mainScreen;
	javax.swing.GroupLayout layout;

	public ThanksYouScreen(MainScreen mainScreen, javax.swing.GroupLayout layout) {
		this.layout = layout;
		this.mainScreen = mainScreen;
		initComponents();
		command_0 = Util.getUtilInstance().getCommand_0();
		jLabel2.setText("" + command_0.getNAME());
		int total_time = (Integer.parseInt(command_0.getPRETIME()) + Util.getUtilInstance().getTime()+ Integer.parseInt(command_0.getAFTER_TIME()));
		if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("Order Type: "+command_0.getNAME());
		System.out.println("Pre Time: "+command_0.getPRETIME());
		System.out.println("Spa Time: "+Util.getUtilInstance().getTime());
		System.out.println("After Time: "+command_0.getAFTER_TIME());
		System.out.println("Total Spa Time: "+total_time);}
		//		jLabel6.setText("" + total_time + ":00 Min");
		String thanks_messag1 = ContentPropertiesFile.Thanks_Message1;
		thanks_messag1 = thanks_messag1.replace("$massage", command_0.getNAME());
		int time = Util.getUtilInstance().getTime();
		int min = time/60;
	    int sec = time%60;
	       String minSt =""+min;
		 if(min <10){
			 minSt="0"+min;
		}
		String secSt = ""+sec;
		if(sec <10){
			 secSt ="0"+sec;
		}
		thanks_messag1 = thanks_messag1.replace("$time", minSt + ":"+secSt);
		jLabel3.setText(thanks_messag1);
		String thanks_messag2 = ContentPropertiesFile.Thanks_Message2;
		thanks_messag2 = thanks_messag2.replace("$massage", command_0.getNAME());
		time = Integer.parseInt(command_0.getPRETIME());
		min = time/60;
		sec = time%60;
		minSt =""+min;
		 if(min <10){
			 minSt="0"+min;
		}
		secSt = ""+sec;
		if(sec <10){
			 secSt ="0"+sec;
		}
		thanks_messag2 = thanks_messag2.replace("$time", minSt+":"+secSt);
		jLabel4.setText(thanks_messag2);
		
		setTimer();
//		
		MassageTimer massageTimer = new MassageTimer(total_time, command_0.getSOLARIUMID(),Integer.parseInt(command_0.getPRETIME()), Integer.parseInt(command_0.getAFTER_TIME()));
		Hashtable massHash = Util.getUtilInstance().getMassageTimerHash();
		massHash.put(command_0.getSOLARIUMID(), massageTimer);
		
		Hashtable startHash = Util.getUtilInstance().getStartTimeHash();
		TimerCounter timerCounter = new TimerCounter();
		timerCounter.setStartTime(System.currentTimeMillis());
		timerCounter.setTotalTime(total_time);
		startHash.put(command_0.getSOLARIUMID(), timerCounter);
		
		
	}
	
	public void setTimer(){
		timer = new Timer(1000, new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// Code to be executed
				count++;
				if (count == ConfigPropertiesFile.THANKS_SCREEN_TIMEOUT_MS/1000) {
					timer.stop();
				       MainScreen leoSpaMainFrame = new MainScreen();
				       leoSpaMainFrame.setVisible(true);
				       mainScreen.dispose();
				}
			}
		});
		timer.setRepeats(true); // Only execute once
		timer.start(); // Go go go!
	}

	public void setLayout(){
		 layout = new javax.swing.GroupLayout(mainScreen.getContentPane());
		 mainScreen.getContentPane().setLayout(layout);
	        layout.setHorizontalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
	                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(75, 75, 75))
	        );
	        layout.setVerticalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
	                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(94, 94, 94))
	        );


	        mainScreen.pack();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		 jDialog1 = new javax.swing.JDialog();
	        jPanel1 = new javax.swing.JPanel();
	        jPanel2 = new javax.swing.JPanel();
	        jLabel1 = new javax.swing.JLabel();
	        jLabel2 = new javax.swing.JLabel();
	        jLabel3 = new javax.swing.JLabel();
	        jLabel7 = new javax.swing.JLabel();
	        jLabel4 = new javax.swing.JLabel();

	        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
	        jDialog1.getContentPane().setLayout(jDialog1Layout);
	        jDialog1Layout.setHorizontalGroup(
	            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 400, Short.MAX_VALUE)
	        );
	        jDialog1Layout.setVerticalGroup(
	            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 300, Short.MAX_VALUE)
	        );


	        jPanel1.setMaximumSize(new java.awt.Dimension(800, 1280));
	        jPanel1.setMinimumSize(new java.awt.Dimension(800, 1280));
	        jPanel1.setOpaque(false);
	        jPanel1.setPreferredSize(new java.awt.Dimension(800, 1280));

	        jPanel2.setBackground(new java.awt.Color(152, 63, 200));
	        jPanel2.setPreferredSize(new java.awt.Dimension(786, 768));

	        jLabel1.setBackground(new java.awt.Color(105, 135, 182));
	        jLabel1.setFont(new java.awt.Font("SansSerif", 1, 40)); // NOI18N
	        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        jLabel1.setText(ContentPropertiesFile.Thanks_Message);
	        jLabel1.setOpaque(true);

	        jLabel2.setFont(new java.awt.Font("SansSerif", 1, 45)); // NOI18N
	        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

	        jLabel3.setFont(new java.awt.Font("SansSerif", 0, 45)); // NOI18N
	        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        	        
	        jLabel4.setFont(new java.awt.Font("SansSerif", 0, 40)); // NOI18N
	        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        
	        jLabel7.setFont(new java.awt.Font("SansSerif", 1, 45)); // NOI18N
	        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        jLabel7.setText("Ihr Studio Team");

	        

	     
	        //=============================
	        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
	        jPanel2.setLayout(jPanel2Layout);
	        jPanel2Layout.setHorizontalGroup(
	            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel2Layout.createSequentialGroup()
	                .addContainerGap()
	                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
	                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
	                    .addComponent(jLabel4)
	                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
	                .addContainerGap())
	        );
	        jPanel2Layout.setVerticalGroup(
	            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel2Layout.createSequentialGroup()
	                .addGap(96, 96, 96)
	                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(61, 61, 61)
	                .addComponent(jLabel2)
	                .addGap(50, 50, 50)
	                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(50, 50, 50)
	                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addGap(61, 61, 61)
	                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(77, Short.MAX_VALUE))
	        );
	        //=========================

	        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
	        jPanel1.setLayout(jPanel1Layout);
	        jPanel1Layout.setHorizontalGroup(
	            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel1Layout.createSequentialGroup()
	                .addGap(0, 0, 0)
	                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(150, Short.MAX_VALUE))
	        );
	        jPanel1Layout.setVerticalGroup(
	            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel1Layout.createSequentialGroup()
	                .addGap(0, 0, 0)
	                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(730, Short.MAX_VALUE))
	        );

	       
	}// </editor-fold>
	
	
	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

		// this.dispose();
		// new LoadingScreen().setVisible(true);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	// public static void main(String args[]) {
	// /* Set the Nimbus look and feel */
	// //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code
	// (optional) ">
	// /* If Nimbus (introduced in Java SE 6) is not available, stay with the
	// default look and feel.
	// * For details see
	// http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
	// */
	// try {
	// for (javax.swing.UIManager.LookAndFeelInfo info :
	// javax.swing.UIManager.getInstalledLookAndFeels()) {
	// if ("Nimbus".equals(info.getName())) {
	// javax.swing.UIManager.setLookAndFeel(info.getClassName());
	// break;
	// }
	// }
	// } catch (ClassNotFoundException ex) {
	// java.util.logging.Logger.getLogger(ThanksYouScreen.class.getName()).log(java.util.logging.Level.SEVERE,
	// null, ex);
	// } catch (InstantiationException ex) {
	// java.util.logging.Logger.getLogger(ThanksYouScreen.class.getName()).log(java.util.logging.Level.SEVERE,
	// null, ex);
	// } catch (IllegalAccessException ex) {
	// java.util.logging.Logger.getLogger(ThanksYouScreen.class.getName()).log(java.util.logging.Level.SEVERE,
	// null, ex);
	// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
	// java.util.logging.Logger.getLogger(ThanksYouScreen.class.getName()).log(java.util.logging.Level.SEVERE,
	// null, ex);
	// }
	// //</editor-fold>
	// //</editor-fold>
	// //</editor-fold>
	// //</editor-fold>
	// //</editor-fold>
	// //</editor-fold>
	// //</editor-fold>
	// //</editor-fold>
	//
	// /* Create and display the form */
	// java.awt.EventQueue.invokeLater(new Runnable() {
	// public void run() {
	// new ThanksYouScreen().setVisible(true);
	// }
	// });
	// }

	// Variables declaration - do not modify
	 private javax.swing.JDialog jDialog1;
	    private javax.swing.JLabel jLabel1;
	    private javax.swing.JLabel jLabel2;
	    private javax.swing.JLabel jLabel3;
	    private javax.swing.JLabel jLabel4;
	    private javax.swing.JLabel jLabel7;
	    private javax.swing.JPanel jPanel1;
	    private javax.swing.JPanel jPanel2;
	// End of variables declaration
}
